package com.jpcc.vw.onlineRadio.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jpcc.vw.onlineRadio.R;
import com.jpcc.vw.onlineRadio.model.bean.HotwordsEntity;
import com.jpcc.vw.onlineRadio.utils.ViewHolderUtils;

import java.util.ArrayList;
import java.util.List;

public class HotwordsAdapter extends BaseAdapter {


    private List<HotwordsEntity> datas = new ArrayList<>();
    private Context context;

    public HotwordsAdapter(Context c, List<HotwordsEntity> sources) {
        if (sources != null) {
            datas.clear();
            datas.addAll(sources);
            context=c;
        }
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_search_history, null);
        }
        initViews(position, convertView);
        return convertView;
    }

    public void setDatas(List<HotwordsEntity> sources) {
        if (sources != null) {
            datas.clear();
            datas.addAll(sources);
            notifyDataSetChanged();
        }
    }

    private void initViews(int position, View convertView) {
        final HotwordsEntity entity = datas.get(position);
        TextView tv_calendar_date = ViewHolderUtils.get(convertView, R.id.tv_item_search_history);
        tv_calendar_date.setText(entity.getSearchWord());
    }
}
